<?php

require_once 'Base.php';

class CategoryModel extends Base {
	
	public function getList($where = [], $page= 0, $pagesize= 10){
		
		//$where['id = ?'] = 1;
		if($where) $this->where($where);
		
		//$limit = "0,1";
		if($limit) $this->limit($limit);
		
		
		return $this->select();
	}
	
	public function getListByIds($ids = []){
		
		$data = $this->getList(['catid in (?)' => $ids],0,0);	
		
		$list = [];
		foreach($data as $val){
			$list[$val['catid']] = $val;
		}
		
		return $list;
	}
	
	public function getOne($where = []){
		
		//$where['id = ?'] = 1;
		if($where) $this->where($where);
		
		return $this->fetch();
	}
	
	public function getCount($where=[]){
		//$sql = "SELECT count(*) FROM shop_goods_category where 1=1";
		$this->_db = $this->getAdapter();
    	$select = $this->_db->select();
		
		$select->from('shop_category',"count(*) as total");
		 foreach ($where as $key => $val) {
            if (is_int($key)) {
               
               $select->where($val);
            } else {
              
                $select->where($key, $val);
            }
	     }   

		return $this->_db->fetchRow($select);
		
	}
	
	public function get_goods_category($where ='', $limit = ''){
		
		$this->_db = $this->getAdapter();
    	$select = $this->_db->select();
    	$select->from('shop_goods_category');
    	
	     foreach ($where as $key => $val) {
            if (is_int($key)) {
               
               $select->where($val);
            } else {
              
                $select->where($key, $val);
            }
	     }   
    	//if($pagesize) $select->limit($pagesize,$page*$pagesize); 
    	return $this->_db->fetchAll($select);
	
	
		return $this->select();
	}
}
